#include <stdio.h>  
#include <signal.h>

#ifdef WIN32
#define WIN32_LEAN_AND_MEAN  
#include <windows.h>  
#include <winsock2.h>  
#endif

#include <zsystem/httpServer/httpserver.h>
#include <zsystem/core/threading/thread.h>


void 
callback(zsystem::httpRequest* req, Z_PTR arg)
{
}

Z_BOOL g_exit=Z_FALSE;
void
sigint(int s) {
  g_exit = true;
}

int
main(int argc, char ** argv)
{
#ifdef WIN32
#define BIND_ADDRESS "ip4:127.0.0.1"
#define BIND_PORT 2345
#define THREAD_NUMBER 2
#define BACKLOG 100
  WSADATA wsaData;  
  DWORD Ret;  
  if ((Ret = WSAStartup(MAKEWORD(2, 2), &wsaData)) != 0)  {  
    printf("WSAStartup failed with error %d\n", Ret);  
    return -1;  
  }  
#else
#define BIND_ADDRESS "unix:/tmp/httpServer_unittest.sock"
#define BIND_PORT 0
#define THREAD_NUMBER 2
#define BACKLOG 100
#endif

  zsystem::httpServerM* server = Z_NEW(zsystem::httpServerM)(BIND_ADDRESS, BIND_PORT, THREAD_NUMBER, BACKLOG);
  server->setCallback("", callback, Z_NULL);
  server->start();
  
  signal(SIGINT, sigint);
  while(!g_exit)
  {
    zsystem::ssleep(5);
  };
  server->stop();
  Z_SAFE_DELETE(server, ~httpServer);
#ifdef WIN32
  WSACleanup();  
#endif
  return 0;  
}  

